package com.imooc.miaosha.util;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import java.util.*;

public class HashMapCompareUtil {
    public static Map<String, Integer> compare(Map<String, Integer> maps) {
        HashMapComparator hashMapComparator = new HashMapComparator();
        List<Map.Entry<String, Integer>> entryList = Lists.newArrayList();
        entryList.addAll(maps.entrySet());
        Collections.sort(entryList, hashMapComparator);
        Map<String, Integer> newMap = Maps.newHashMap();
        for (Iterator<Map.Entry<String, Integer>> it = entryList.iterator(); it.hasNext(); ) {
            newMap.put(it.next().getKey(), it.next().getValue());
        }
        return newMap;
    }
}
